from typing import List

from dao.score_dao import ScoreDao
from model.score_model import ScoreModel

score_dao = ScoreDao()


class ScoreService:
    def create(self, model: ScoreModel) -> int:
        """
        创建
        """
        return score_dao.create(model)

    def update(self, model: ScoreModel) -> int:
        """
        更新
        """
        if score_dao.get(model.id):
            score_dao.update(model)
        return model.id

    def delete(self, id: int) -> int:
        """
        删除
        """
        if self.get(id):
            return score_dao.delete(id)

    def list(self) -> List[ScoreModel]:
        """
        获取全部
        """
        return score_dao.list()

    def get(self, id: int) -> ScoreModel:
        """
        获取某个数据
        """
        return score_dao.get(id)

    def get_by_name(self, name) -> ScoreModel:
        """
        根据名称获取某个数据
        """
        return score_dao.get_by_name(name=name)